package com.ruoyi.utils;

import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.UnsupportedEncodingException;
import java.util.UUID;

/**
 * @Author： yu.Tan
 * @Date: 2020/8/20 10:49
 * @Description:
 */
public class RabbitMqSend {

    @Autowired
    private RabbitTemplate template;

    Boolean sendDirect(String exchange,String routingKey,String msg){
        try {
            //消息的UUID 唯一标识
            CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
            template.convertAndSend(exchange,routingKey,msg.getBytes("UTF-8"),correlationData);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }
}
